package com.heima.search.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.search.dtos.UserSearchDto;
import com.heima.search.service.IAssociateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * 联想词
 */
@RestController
@RequestMapping("/api/v1/associate")
public class AssociateController {

    @Autowired
    private IAssociateService associateService;
    /**
     * 自动补全功能
     * @param dto
     * @return
     */
    @PostMapping("/search")
    public ResponseResult search(@RequestBody UserSearchDto dto){
        try {
            return associateService.search(dto);
        } catch (IOException e) {
            e.printStackTrace();
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID,"出现异常了");
        }
    }
}
